home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / CDTools / GoFetch! / arexx / Stephen_Bridges / yam2gofetch.rexx < prev   
OS/2 REXX Batch file  |  1999-11-04  |  7KB  |  258 lines

  1. /* $VER:Yam2GoFetch!.rexx 0.8ß (04 Nov 99) Steve Bridges
  2. ** 
  3. ** Stephen Bridges    <steve@bh01.demon.co.uk>
  4. **
  5. ** An Arexx script to use GoFetch! to batch download Aminet files
  6. ** from any Aminet recent file by pasting them in with Powersnap.
  7. **
  8. */
  9.  
  10. OPTIONS RESULTS
  11.  
  12. /*
  13. ** INSTRUCTIONS
  14. **
  15. ** Please alter the path to GoFetch! and Miami to suit your set-up.
  16. ** Change the Miami settings for your set-up.
  17. ** Please enter the address and path to your nearest Aminet site.
  18. ** Also enter the path/filename where you want the batchfile to be saved.
  19. */
  20.  
  21. gofetch_path = 'AmiTCP:GoFetch/GoFetch!'
  22. miami_path =   'AmiTCP:Miami/Miami'
  23. settings =     'Miami:Miami.default'
  24.  
  25. site =         'ftp.demon.co.uk'
  26. dir_address =  '/pub/mirrors/aminet/'
  27.  
  28. batch_path =   'Yam:gofetch.batch'
  29.  
  30. /*
  31. ** DO NOT CHANGE ANYTHING BELOW HERE UNLESS YOU KNOW WHAT
  32. ** YOU ARE DOING, ALTHOUGH THAT DIDN'T STOP ME. :-)
  33. */
  34.  
  35. /* Initialisation */
  36.  
  37. port =     '21'
  38.  
  39. FTP_PORT = 'GOFETCH'
  40. TCP_PORT = 'MIAMI.1'
  41.  
  42. temp_path = 'Ram:T/gofetch.batch'
  43.  
  44. title =            'yam2gofetch!.rexx 0.8ß by Steve Bridges'
  45. path_text =        '  Please paste in a file and directory  '
  46. save_text =        'Do you want to get those files now' ||'0a'x|| 'or save the batchfile and get them' ||'0a'x|| 'later with batch2gofetch!.rexx?'
  47. add_text =         ''batch_path' already exists,' ||'0a'x|| 'do you want to add to it or replace it?'
  48.  
  49. f_error_text =     'ERROR:  You clipped the wrong bit,' ||'0a'x|| 'you need the the whole line up to the size'
  50.  
  51. g_error_text =     'ERROR:  Unable to launch GoFetch' ||'0a'x|| 'Did you amend the path in the script?'
  52. m_error_text =     'ERROR:  Unable to launch Miami' ||'0a'x|| 'Did you amend the path in the script?'
  53. m_on_error_text =  'ERROR:  Miami unable to go on-line' ||'0a'x|| 'Is your modem switched on and plugged in? :-)'
  54. m_set_error_text = 'ERROR:  Miami unable to load settings' ||'0a'x|| 'Did you amend the settings in the script?'
  55. t_error_text =     'ERROR:  Unable to open 'temp_path' for reading' ||'0a'x|| 'Something is badly wrong, please get in touch'
  56. old_error_text =   'ERROR:  Unable to open 'batch_path' for writing' ||'0a'x|| 'Did you amend the settings in the script?'
  57. d_error_text =     'ERROR:  Unable to delete 'temp_path'' ||'0a'x|| 'Something has a lock on 'temp_path''  
  58. open_error_text =  'ERROR:  Unable to open 'temp_path' for writing' ||'0a'x|| 'Something is badly wrong, please get in touch'
  59.  
  60. exit_buttons =           '_Exit'
  61. save_or_get_buttons =    '_Now|_Save'
  62. add_or_replace_buttons = '_Add|_Replace|_Exit'
  63.  
  64. another_buttons =        'Another|Last One|Exit'
  65.  
  66. /* Check if rexxreqtools.library/rexxsupport.library is installed */
  67.  
  68. IF ~EXISTS('Libs:rexxreqtools.library') THEN CALL LIBRARY_ERROR()
  69. IF ~EXISTS('Libs:rexxsupport.library') THEN CALL LIBRARY_ERROR()
  70.  
  71. /* Add rexxreqtools.library/rexxsupport.library to functions */
  72.  
  73. IF ~SHOW('L','rexxreqtools.library') THEN ADDLIB('rexxreqtools.library', 5, -30, 0)
  74. IF ~SHOW('L','rexxsupport.library') THEN ADDLIB('rexxsupport.library', 0, -30, 0)
  75.  
  76. /* Open file for batch */
  77.  
  78. IF ~OPEN('batch_file',temp_path,'W') THEN CALL SCRIPT_ERROR(open_error_text)
  79.  
  80. /*  Get the files */
  81.  
  82. DO UNTIL go_on = 2
  83.  go_on = get_address()
  84. END
  85.  
  86. CALL CLOSE('batch_file')
  87.   
  88. /* Ask if the user wants to get them now? */
  89.  
  90. save_or_get = RTEZREQUEST(save_text,save_or_get_buttons,title,,)
  91. IF save_or_get = 0 THEN DO
  92.  
  93. /* Add new additions to batchfile */
  94.  
  95.  IF EXISTS(batch_path) THEN DO
  96.   add_or_replace = RTEZREQUEST(add_text,add_or_replace_buttons,title,,)
  97.   IF add_or_replace = 0 THEN EXIT
  98.   IF add_or_replace = 1 THEN DO
  99.    IF ~OPEN('old_file',batch_path,'A') THEN CALL SCRIPT_ERROR(old_error_text)
  100.    IF ~OPEN('batch_file',temp_path,'R') THEN CALL SCRIPT_ERROR(open_error_text)
  101.    file = READCH('batch_file',65535)
  102.    CALL WRITECH('old_file',file)
  103.    CALL CLOSE('batch_file')
  104.    CALL CLOSE('old_file')
  105.   END
  106.  END
  107.  
  108. /* Save batchfile */
  109.  
  110.  IF ~EXISTS(batch_path) | add_or_replace = 2 THEN DO 
  111.   ADDRESS COMMAND
  112.   'SYS:C/COPY 'temp_path' to 'batch_path''
  113.   IF ~DELETE(temp_path) THEN CALL SCRIPT_ERROR(d_error_text)
  114.  END
  115.  EXIT
  116. END
  117.  
  118. /* Get Miami running */
  119.  
  120. IF ~SHOW('P',TCP_PORT) THEN DO
  121.  ADDRESS COMMAND
  122.  'RUN >NIL:' miami_path nogui
  123.  'SYS:rexxc/WaitForPort' TCP_PORT
  124.  IF RC>0 THEN CALL SCRIPT_ERROR(m_error_text)
  125. END
  126.  
  127. /* Miami Online */
  128.  
  129. ADDRESS (TCP_PORT)
  130. LOADSETTINGS settings
  131. IF RC>0 THEN CALL SCRIPT_ERROR(m_set_error_text)
  132. ISONLINE
  133. IF RC=0 THEN DO
  134.  ONLINE
  135.  ISONLINE
  136.  IF RC=0 THEN CALL SCRIPT_ERROR(m_on_error_text)
  137. END
  138.  
  139. /* Get GoFetch Running */
  140.  
  141. IF ~SHOW('P',FTP_PORT) THEN DO
  142.  ADDRESS COMMAND
  143.  'RUN >NIL:' gofetch_path
  144.  'SYS:rexxc/WaitForPort' FTP_PORT
  145.  IF RC>0 THEN CALL SCRIPT_ERROR(g_error_text)
  146. END
  147.  
  148. /* Open file in T: */
  149.  
  150. IF ~OPEN('created_file',temp_path,'R') THEN CALL SCRIPT_ERROR(t_error_text)
  151.  
  152. /* Get settings from GoFetch! */
  153.  
  154. ADDRESS (FTP_PORT)
  155. GETDOWNLOADPATH
  156. localpath = RESULT
  157.  
  158. /* Create profile list in GoFetch! */
  159.  
  160. DO UNTIL EOF('created_file')
  161.  remotepath = READLN('created_file')
  162.  filename = READLN('created_file')
  163.  ADDANONPROFILE site port remotepath filename localpath
  164. END
  165.  
  166. CALL CLOSE('created_file')
  167.  
  168. /* Go get the files */
  169.  
  170. GOFETCH
  171. /*
  172. DO UNTIL finished = 1
  173.  DOWNLOADING?????
  174.  finished = RESULT
  175.  CALL DELAY(5*50)     ***This bit needs re-doing as and when you add the appropriate command***
  176. END
  177.  
  178. /* Quit GoFetch! */
  179.  
  180. QUITGOFETCH 
  181. */
  182. /* Delete file in T: */
  183.  
  184. IF ~DELETE(temp_path) THEN CALL SCRIPT_ERROR(d_error_text)
  185.  
  186. EXIT
  187.  
  188. /* ----------Create function() script_error---------- */
  189.  
  190. script_error:
  191.  
  192. PARSE ARG text
  193.  
  194. error = RTEZREQUEST(text,exit_buttons,title,,)
  195. IF error=0 THEN EXIT
  196.  
  197. /* ----------Create get_address function()---------- */
  198.  
  199. get_address:
  200.  
  201. /* Put up string requester */
  202.  
  203. site_address = RTGETSTRING(,path_text,title,another_buttons,,)
  204. last_one = RTRESULT
  205. IF last_one = 0 THEN EXIT
  206.  
  207. /* Check string for correct clip */
  208.  
  209. IF ~CHECK_ERROR(site_address) THEN CALL SCRIPT_ERROR(f_error_text)
  210.  
  211. /* Pull apart the string and rearrange */
  212.  
  213. site_address = LEFT(site_address,30)
  214. site_address = COMPRESS(site_address)
  215.  
  216. lha_pos = POS('.lha',site_address)
  217.  
  218. file_name = LEFT(site_address,lha_pos+3)
  219. path_name = SUBSTR(site_address,lha_pos+4)
  220. path_name = dir_address||path_name||'/'
  221. full_name = path_name||file_name
  222.  
  223. /* Build up the batch file */
  224.  
  225. CALL WRITELN('batch_file' ,path_name)
  226. CALL WRITELN('batch_file' ,file_name)
  227.  
  228. RETURN last_one
  229.  
  230. /*  ---------Create error_checking function()----------*/
  231.  
  232. check_error: PROCEDURE
  233.  
  234. ARG next_line
  235.  
  236. /*Check string for correct clip */
  237.  
  238. gap_pos1 = SUBSTR(next_line,19,1)
  239. IF gap_pos1 ~= ' ' THEN c = 0
  240. ELSE c = 1
  241.  
  242. slash_pos = POS("/",next_line)
  243. IF slash_pos~=23 & slash_pos~=24 THEN d = 0
  244. ELSE d = 1
  245.  
  246. IF c = 1 & d = 1 THEN RETURN 1
  247. ELSE RETURN 0
  248.  
  249. /* ----------Create library_error function()---------- */
  250.  
  251. library_error:
  252.  
  253. DO
  254.  ADDRESS COMMAND
  255.  'C:RequestChoice PUBSCREEN="Workbench" TITLE="yam2gofetch!.rexx v0.8ß by Steve Bridges" BODY=" Could not execute Arexx script. *n Please check you have rexxreqtools.library *n and rexxsupport.library installed in Libs:" GADGETS="Exit" >NIL:'
  256.  IF RC=0 THEN EXIT
  257. END
  258.